

import 'package:bt_tool/basic/bt_api_manager.dart';
import 'package:bt_tool/basic/bt_color_tool.dart';
import 'package:bt_tool/basic/bt_common_define.dart';
import 'package:bt_tool/basic/bt_language_tool.dart';
import 'package:bt_tool/basic/bt_nav_tool.dart';
import 'package:bt_tool/basic/bt_shared_preferences.dart';
import 'package:bt_tool/basic/bt_theme_color.dart';
import 'package:bt_tool/widget/bt_loading_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_demo/common/config/app_theme_color_config.dart';

class AppConfig {

  //是否需要显示引导页，本地存储的值小于该版本号的就需要显示
  static const appLeadPageVersion = 100;
  static const String appLeadPageKey = "BTAppInfoLeadPageKey";

  //配置的中台数据前缀名称
  static const String appDataStartName = "bt_";

  int requestConfigFailNum = 0;

  static AppConfig? _instance;

  static AppConfig share(){
    _instance ??= AppConfig._internal();
    return _instance!;
  }

  AppConfig._internal();

  static Image userIconErrorDefaultImg(double size){
    return Image.asset(btPngPath("bt/bt_default_icon"),width: size,height: size,);
  }

  //app是否需要登录使用
  static bool isAppNeedLoginToUse(){
    return false;
  }

  //是否需要显示引导页
  static bool isNeedShowLeadPage(){

    // return true;

    // int versionNow = BTSharedPreferences.get(appLeadPageKey, 0);
    // if(versionNow < appLeadPageVersion){
    //   return true;
    // }

    return false;
  }

  //更新引导页本地存储版本到最高版本号
  static void updateShowLeadPageVersion(){
    BTSharedPreferences.save(appLeadPageKey, appLeadPageVersion);
  }

  //配置环境api地址
  static Future<void> configApi() async {
    int apiVersion = 4;
    List<BTApiModel> modelList = [
      BTApiModel.createModel(
          name: "product",
          apiUrl: "https://api.aitoolme.com",
          extra: "",
          channel: "aifaios2001"),

      BTApiModel.createModel(
          name: "test",
          apiUrl: "http://192.168.0.236:8080",
          extra: "",
          channel: "aifaios2001"),
    ];
    await BTApiManager.share().createApiIfNotExist(modelList, apiVersion);
  }

  //配置主题颜色
  static configTheme(){
    BTThemeColorConfig config = BTThemeColorConfig();
    config.mainColor = btRGBColor(255, 98, 73);
    config.contentBgColor = Colors.white;
    config.contentBgColor2 = btRGBColor(245, 245, 245);
    config.textColor = btHexColor("#333333");
    config.navBgColor = config.mainColor;
    BTThemeColor.share().colorConfig = config;

  }

  static BTPageLoadingConfig loadingConfig(){
    return BTPageLoadingConfig(
      emptyTips: "暂无数据".btTrans,
      errorStr: "出错了".btTrans,
      bgColor: AppThemeColor.contentBgColor,
      loadingStr: "".btTrans,
      mainColor: Colors.white,
      textStyle: const TextStyle(
        color: Colors.white
      )
    );
  }

}
















